#pragma once
#include <myFs/bitmap.h>
#include <myFs/fscomponent.h>
#include <string>
#include <vector>

namespace myFs {
namespace basic {
using size_t = uint32_t;
class FSbasic {
  public:
    FSbasic(::std::string str = "dumpfile");
    ~FSbasic();

  public:
    size_t  toInum(std::string const& path);
    Inode&  toInode(size_t inum);
    void    freeInode(size_t inum);
    void    readdir(size_t inum, std::vector<DirEntry>& dir);
    size_t  dirLookup(size_t inum, std::string const& filename);
    void    initDirInode(size_t inum);
    void    initFileInode(size_t inum);
    void    removeDirEntry(size_t parentInum, size_t inum);
    void    addDirEntry(size_t pinum, DirEntry const& de);
    Bitmap* getBmap();
    Bitmap* getImap();
    size_t  getRootInum() const;

  private:
    void mapFileIntoMemory(std::string const& filename);
    void buildMeta();
    void buildBitmap();
    void parserPath(std::string const& path, std::vector<std::string>& res);

  private:
    void*  m_baseptr;
    size_t m_size;
    int    m_fd;
    Meta   m_meta;
    Bitmap m_inodeBitmap;
    Bitmap m_blockBitmap;
};
}  // namespace basic
}  // namespace myFs